package com.lwj.liwanjia.presenter;

import com.lwj.liwanjia.bean.HomeBean;
import com.lwj.liwanjia.impl.HomeClassifyView;
import com.lwj.liwanjia.model.HomeClassifyModel;

import rx.Subscriber;

/**
 * 首页分类
 */

public class HomeClassifyPresenter {
    private HomeClassifyView homeClassifyView;
    private HomeClassifyModel homeClassifyModel;

    public HomeClassifyPresenter(HomeClassifyView homeClassifyView) {
        this.homeClassifyView = homeClassifyView;
        homeClassifyModel = new HomeClassifyModel();
    }

    public void getClassifyData() {
        if (homeClassifyView != null) {
            homeClassifyModel.getClassifyData(new Subscriber<HomeBean>() {
                @Override
                public void onCompleted() {
                    homeClassifyView.hideProgress();
                }

                @Override
                public void onError(Throwable e) {
                    homeClassifyView.showError((Exception) e);
                    homeClassifyView.hideProgress();
                }

                @Override
                public void onNext(HomeBean homeBean) {
                    homeClassifyView.getClassifyData(homeBean);
                }

                @Override
                public void onStart() {
                    super.onStart();
                    homeClassifyView.showProgress();
                }
            });
        }
    }
}
